package edu.contoller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import edu.annotations.LoginRequired;
import edu.entity.Do.Store;
import edu.mapper.StoreMapper;
import edu.utils.JwtUtil;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;


@RestController
@RequestMapping(value = "/business")
@CrossOrigin(origins = "*",maxAge = 3600)
public class StoreController {

    @Resource
    StoreMapper storeMapper;

    @LoginRequired
    @RequestMapping(value = "/getStoreByBusinessId",method = RequestMethod.GET)
    public Store getStoreByBusinessId(HttpServletRequest request) {
        String token = request.getHeader("token");
        Integer id = Integer.parseInt(JwtUtil.getClaims(token).get("id").asString());
        Store store = storeMapper.selectOne(
                new QueryWrapper<Store>()
                        .eq("business_id", id)
        );
        return store;
    }
}
